package net.xiangcaowuyu.cacheredis.service.impl;

import net.xiangcaowuyu.cacheredis.entity.User;
import net.xiangcaowuyu.cacheredis.service.UserService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @author laughing
 * @date 2020-10-10
 */
@Service
@CacheConfig(cacheNames = "cacheName")
public class UserServiceImpl implements UserService {


    /**
     * 根据Id查找用户
     *
     * @param id 用户Id
     * @return 用户
     */
    @Override
    @Cacheable(key = "#id")
    public User findUserById(int id) {
        User user = new User(id,"张三");
        return user;
    }

    /**
     * 根据Id更新用户信息
     *
     * @param user 用户
     * @return 用户
     */
    @Override
    @CachePut(key = "#user.id")
    public User updateUserById(User user) {
        return user;
    }

    /**
     * 根据Id删除用户
     *
     * @param id 用户Id
     */
    @Override
    @CacheEvict(key = "#id")
    public void deleteUserById(int id) {

    }
}
